<?php
namespace app\index\model;
use think\Model;

class Question extends Model
{
    public function getOne ($where) {
        $res = $this->where($where)->find();
        if($res) {
            return $res->toArray();
        }
        return false;
    }
    
    public function getList ($where) {
        $res = $this->where($where)->select();
        if($res) {
            return $res->toArray();
        }
        return false;
    }
    /*
     * 随机获取一条数据
     */
    public function getRandData ($where=1,$old=[]) {
        if(!empty($old)) {
            $where['id'] = [
                'not in', $old
            ];
        }
        $count = $this->where($where)->count();
        $idx = rand(0,$count-1);
        return $this->where($where)->limit(0,$idx)->find()->toArray();
    }
}
